home *** CD-ROM | disk | FTP | other *** search
- Path: bubba.NMSU.Edu!usenet
- From: ghenniga@ampere.NMSU.Edu (Gary Hennigan)
- Newsgroups: comp.lang.c
- Subject: Re: system() & error detection
- Date: 27 Feb 1996 08:42:01 -0700
- Organization: New Mexico State University - Electromagnetics Group
- Sender: ghenniga@ampere.NMSU.Edu
- Message-ID: <rht4tsclqra.fsf@ampere.NMSU.Edu>
- References: <4gt24g$dba@ncar.ucar.edu>
- Reply-To: ghenniga@NMSU.Edu
- NNTP-Posting-Host: ampere.nmsu.edu
- In-reply-to: jadams@sage.cgd.ucar.edu's message of 26 Feb 1996 19:36:48 GMT
- X-Newsreader: Gnus v5.1
-
- In an article jadams@sage.cgd.ucar.edu (James Adams) wrote:
- > I am attempting to use the system() call in order to have a
- >user-specified command execute in my program.
- >
- > I am wondering how I can check whether or not the command has
- >completed successfully ? I don't want the program to continue if the
- >call I make from system() produces some sort of error. I'd like to be
- >able to do something like the following:
- >
- > result = system(command);
- > if (result == ERROR)
- > exit(0);
- >
- >Is there anyway to do this ? Should I be using something other than
- >system() ?
-
- You may want to read the man page on system(). According to mine the
- system() function returns -1 if it can't execute the requested string,
- or returns the exit status of the shell if the command can be
- executed. Since the exit status of the shell is the exit status of the
- last command executed by the shell you effectively get the exit status
- of the requested command. So, if the requested command exits with
- status 0 when successful, as they commonly do, you can test to see if
- the command executed without error.
-
- Gary
- (ghenniga@NMSU.Edu)
-